package com.cdwh.joylife.utils;

import android.widget.ImageView;


import com.bumptech.glide.Glide;
import com.cdwh.joylife.App;
import com.cdwh.joylife.net.Urls;

import java.util.ArrayList;

/**
 * Created by huxing on 2018/1/26.
 */

public class ImageUtils {
    public static void showImage(String path, ImageView imageView) {

        if (path.contains("/app/base/file/image")) {
            Glide.with(App.getContext()).load(new StringBuffer().append(Urls.FILE_BASE_URL)
                    .append(path).toString()).into(imageView);
        } else {
            //本地图片
            Glide.with(App.getContext()).load(path).into(imageView);
        }
    }

    public static void showImage(int imageId, ImageView imageView) {

        Glide.with(App.getContext()).load(new StringBuffer().append(Urls.FILE_IMAGE_URL).append(imageId).toString()).into(imageView);
    }

    public static ArrayList<String> getImageUrls(ArrayList<String> images) {
        ArrayList<String> mImages = new ArrayList<>();
        for (String path : images) {
            if (path.contains("/app/base/file/image")) {
                mImages.add(getNetUrl(path));
            } else {
                mImages.add(path);
            }
        }

        return mImages;
    }

    private static String getNetUrl(String path) {
        String s = new StringBuffer().append(Urls.FILE_BASE_URL)
                .append(path).toString();

        return s;
    }
}
